import { request } from '@/utils/request'

//任务用户状态枚举
export function orderUserStatusEnum(key) {
    let dic = {
        1: "未派单",
        2: "已派单",
        3: "待接单",
        4: "处理中",
        5: "已完成",
        6: "已驳回",
    }
    return dic[key] ? dic[key] : "未知"
}

//任务状态枚举
export function orderTaskStatusEnum(key) {
    let dic = {
        0: "待开始",
        1: "待接单",
        2: "进行中",
        3: "已完成",
        4: "驳回",
        5: "异常完成",
    }
    return dic[key] ? dic[key] : "未知"
}

//印染颜色选择
export function dyeColorFilter(data, callback) {
    return request({
        url: '/dye_color/list',
        method: 'get',
        data,
        isYarn: true,
    }, callback);
}

//增加颜色
export function addDyeColor(data, callback) {
    return request({
        url: "/dye_color/change",
        method: "post",
        type: "json",
        data,
        isYarn: true
    }, callback);
}

//增加订单
export function addOrder(data, callback) {
    return request({
        url: "/cloth_order/add",
        method: "post",
        type: "json",
        data,
        isYarn: true
    }, callback);
}

//加载订单
export function loadClothOrder(data, callback) {
    return request({
        url: '/cloth_order/list',
        method: 'get',
        data,
        isYarn: true,
    }, callback);
    /*if(data.pageNum == 1) {
        return callback({"totalRow":4,"pageNumber":1,"totalPage":2,"pageSize":3,"list":[{"ordererId":104,"channel":1,"type":2,"orderAt":"2022-08-14 14:22:14","customerName":"张家港道本_蒯圣兵","specialRemark":"","totalNum":11,"operatingTasks":[],"customerId":697,"deliveryAt":"2022-08-14","details":[{"metre":123,"color":"1","num":11,"id":1018,"designNo":"211900白"}],"id":1010,"totalMetre":123.0,"ordererName":"王进芸","tasks":[],"status":0},{"ordererId":118,"channel":2,"type":2,"orderAt":"2022-08-13 16:52:28","customerName":"广州陈伟楠_陈伟楠","specialRemark":"乐尔乐","totalNum":76,"operatingTasks":[{"appointorName":"王进芸","executiveName":"","id":1074,"depPostName":"原料仓库","createAt":"2022-08-13 10:37:10","status":1},{"appointorName":"王进芸","executiveName":"","id":1073,"depPostName":"开发设计部","createAt":"2022-08-13 10:37:10","status":1},{"appointorName":"","acceptAt":"2022-08-13 16:53:31","executiveName":"三老板","id":1063,"depPostName":"门市部","createAt":"2022-08-13 08:53:30","status":2}],"customerId":703,"deliveryAt":"2022-08-30","details":[{"metre":1000,"color":"白","num":17,"id":1016,"designNo":"05851"},{"metre":2000,"color":"黑色","num":59,"id":1017,"designNo":"211900"}],"id":1009,"totalMetre":3000.0,"ordererName":"三老板","tasks":[{"id":1074},{"id":1073},{"id":1072},{"id":1065},{"id":1063}],"status":0},{"ordererId":118,"channel":2,"type":2,"orderAt":"2022-08-12 13:13:25","customerName":"柯桥门市部_王林生","specialRemark":"注意品质","totalNum":10,"operatingTasks":[{"appointorName":"三老板","acceptAt":"2022-08-14 10:15:10","executiveName":"王进芸","id":1062,"depPostName":"业务总部","createAt":"2022-08-13 08:44:01","status":2}],"customerId":647,"deliveryAt":"2022-08-12","details":[{"metre":580,"color":"粉色","num":30,"id":1015,"designNo":"1601"}],"id":1008,"totalMetre":580.0,"ordererName":"三老板","tasks":[{"id":1062},{"id":1046}],"status":0}]})
    }
    if(data.pageNum == 2) {
        return callback({"totalRow":4,"pageNumber":2,"totalPage":2,"pageSize":3,"list":[{"ordererId":118,"channel":2,"type":2,"orderAt":"2022-08-12 13:11:46","customerName":"柯桥门市部_王林生","specialRemark":"注意品质","totalNum":10,"operatingTasks":[{"appointorName":"王进芸","executiveName":"","id":1061,"depPostName":"成品仓库","createAt":"2022-08-12 13:37:01","status":1},{"appointorName":"王进芸","acceptAt":"2022-08-12 13:37:10","executiveName":"施华","id":1060,"depPostName":"织造车间","createAt":"2022-08-12 13:37:01","status":2},{"appointorName":"王进芸","executiveName":"","id":1059,"depPostName":"纱线仓库","createAt":"2022-08-12 13:37:01","status":1},{"appointorName":"王进芸","acceptAt":"2022-08-12 13:37:09","executiveName":"刘江平","id":1058,"depPostName":"纺纱车间","createAt":"2022-08-12 13:37:01","status":2},{"appointorName":"王进芸","acceptAt":"2022-08-12 13:38:22","executiveName":"王芹英","id":1057,"depPostName":"散染车间","createAt":"2022-08-12 13:37:01","status":2},{"appointorName":"王进芸","executiveName":"","id":1056,"depPostName":"原料仓库","createAt":"2022-08-12 13:37:01","status":1},{"appointorName":"王进芸","executiveName":"","id":1055,"depPostName":"后整计划","createAt":"2022-08-12 13:36:10","status":1},{"appointorName":"王进芸","executiveName":"","id":1054,"depPostName":"坯布仓库","createAt":"2022-08-12 13:36:10","status":1},{"appointorName":"王进芸","acceptAt":"2022-08-12 13:36:40","executiveName":"何定刚","id":1053,"depPostName":"染整车间","createAt":"2022-08-12 13:36:10","status":2},{"appointorName":"王进芸","acceptAt":"2022-08-12 13:36:34","executiveName":"老板娘","id":1052,"depPostName":"坯染车间","createAt":"2022-08-12 13:36:10","status":2},{"appointorName":"王进芸","acceptAt":"2022-08-12 13:34:14","executiveName":"黄小根","id":1051,"depPostName":"开发设计部","createAt":"2022-08-12 13:33:51","status":2},{"appointorName":"三老板","acceptAt":"2022-08-12 13:28:37","executiveName":"王进芸","id":1049,"depPostName":"业务部","createAt":"2022-08-12 13:24:20","status":2}],"customerId":647,"deliveryAt":"2022-08-12","details":[{"metre":580,"color":"杏","num":10,"id":1013,"designNo":"1601"}],"id":1007,"totalMetre":580.0,"ordererName":"三老板","tasks":[{"id":1061},{"id":1060},{"id":1059},{"id":1058},{"id":1057},{"id":1056},{"id":1055},{"id":1054},{"id":1053},{"id":1052},{"id":1051},{"id":1049},{"id":1048}],"status":0}]});
    }*/
}

//加载子订单
export function loadClothSubOrder(data, callback) {
    return request({
        url: '/cloth_order/list_sub',
        method: 'get',
        data,
        isYarn: true,
    }, callback);
    /*if(data.pageNum == 1) {
        return callback({"totalRow":3,"pageNumber":1,"totalPage":1,"pageSize":3,"list":[{"specialRemark":"特殊没有的","totalNum":26,"ordererId":4,"channel":2,"customerId":647,"deliveryAt":"2022-08-02 21:27:01","id":1005,"totalMetre":1500.0,"type":2,"ordererName":"隔壁老王","orderAt":"2022-08-02 21:27:01","customerName":"柯桥门市部_王林生"},{"specialRemark":"测试下","totalNum":17,"ordererId":4,"channel":3,"customerId":569,"deliveryAt":"2022-08-03 15:15:29","id":1006,"totalMetre":1000.0,"type":2,"ordererName":"隔壁老王","orderAt":"2022-08-03 15:15:29","customerName":"桐乡皙然服饰有限公司_安妮"},{"specialRemark":"这里有\n测试1\n知道a\n摸摸","totalNum":9,"ordererId":4,"channel":3,"customerId":569,"deliveryAt":"2022-08-03 15:20:55","id":1007,"totalMetre":500.0,"type":2,"ordererName":"隔壁老王","orderAt":"2022-08-03 15:20:55","customerName":"桐乡皙然服饰有限公司_安妮"}]})
    }
    if(data.pageNum == 2) {
        return callback({"totalRow":3,"pageNumber":2,"totalPage":2,"pageSize":3,"list":[{"specialRemark":"这里有\n测试1\n知道a\n摸摸","totalNum":9,"ordererId":4,"channel":3,"customerId":569,"deliveryAt":"2022-08-03 15:20:55","id":1008,"totalMetre":500.0,"type":2,"ordererName":"隔壁老王","orderAt":"2022-08-03 15:20:55","customerName":"桐乡皙然服饰有限公司_安妮"}]});
    }*/
}

//修改子订单
export function changeOrder(data, callback) {
    return request({
        url: "/cloth_order/change",
        method: "post",
        type: "json",
        data,
        isYarn: true
    }, callback);
}

//修改子订单
export function changeSubOrder(data, callback) {
    return request({
        url: "/cloth_order/change_sub",
        method: "post",
        type: "json",
        data,
        isYarn: true
    }, callback);
}

//删除子订单
export function cancelSubOrder(data, callback) {
    return request({
        url: "/cloth_order/cancel_sub",
        method: "post",
        data,
        isFile: true,
        isYarn: true
    }, callback);
}

//增加子订单
export function addSubOrder(data, callback) {
    return request({
        url: "/cloth_order/add_sub",
        method: "post",
        type: "json",
        data,
        isYarn: true
    }, callback);
}

//加载坯布库存
export function loadGreyClothStore(data, callback) {
    return request({
        url: '/grey_cloth_store/list_view_4_order',
        method: 'get',
        data,
        isYarn: true,
    }, callback);
    // return callback([{"area":"A,二级临仓","outCount":0,"color":"Y0489#播沙驼","expectNum":0,"totalNum":0,"oldNum":0,"length":-52.8,"designId":776,"weight":-44.4,"id":1100,"newNum":0,"designNo":"211900-A-489-双面呢"},{"area":"A,二级临仓","outCount":0,"color":"Y0488#播亮驼","expectNum":0,"totalNum":0,"oldNum":0,"length":-52.3,"designId":775,"weight":-44.4,"id":1101,"newNum":0,"designNo":"211900-A-488-双面呢"},{"area":"二级临仓","outCount":0,"color":"Y0477#播烟灰","expectNum":0,"totalNum":0,"oldNum":0,"length":0.0,"designId":707,"weight":0.0,"id":1032,"newNum":0,"designNo":"211900-A-477-双面呢"},{"area":"二级临仓","outCount":0,"color":"Y0497#播三驼","expectNum":137,"totalNum":9,"oldNum":0,"length":627.2,"designId":826,"weight":526.6,"id":1166,"newNum":0,"designNo":"211900-A-497-双面呢"}]);
}

//加载成品库存
export function loadProductClothStore(data, callback) {
    return request({
        url: '/product_cloth_store/list_view_4_order',
        method: 'get',
        data,
        isYarn: true,
    }, callback);
    // return callback([{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"P0016#米白","totalNum":109.0,"length":6216.5,"weight":4466.0,"designNo":"05851"},{"exceptNum":1,"color":"米白","totalNum":210.0,"length":5687.3,"weight":4691.1,"designNo":"05851"}]);
}

//设计单纱线
export function loadSampleYarn(data, callback) {
    return request({
        url: '/sample_yarn/list_by_form',
        method: 'get',
        data,
        isYarn: true,
    }, callback);
    // return callback([{"yarnAlias":"A","yarnNo":"0999#本白","designFormId":873,"yarnName":"毛化纤","expectStock":200.6,"standardNo":"12148020999W80N20-y","unitFormat":1,"yarnStandard":48.0,"yarnUsage":24.1,"composition":"[{\"type\":\"W\",\"content\":80,\"moistureRegain\":16.0},{\"type\":\"N\",\"content\":20,\"moistureRegain\":4.5}]","yarnId":8487,"yarnStrandNum":2,"id":16769,"stock":200,"modulus":90.0},{"yarnAlias":"B","yarnNo":"0999#本白","designFormId":873,"yarnName":"毛化纤","expectStock":4354.6,"standardNo":"12185020999P100","unitFormat":1,"yarnStandard":85.0,"yarnUsage":1.4,"composition":"[{\"type\":\"P\",\"content\":100,\"moistureRegain\":0.4}]","yarnId":8003,"yarnStrandNum":2,"id":16770,"stock":4354.0,"modulus":90.0},{"yarnAlias":"A","yarnNo":"0999#本白","designFormId":873,"yarnName":"毛化纤","expectStock":-26144.6,"standardNo":"12148020999W80N20-y","unitFormat":1,"yarnStandard":48.0,"yarnUsage":22.2,"composition":"[{\"type\":\"W\",\"content\":80,\"moistureRegain\":16.0},{\"type\":\"N\",\"content\":20,\"moistureRegain\":4.5}]","yarnId":8487,"yarnStrandNum":2,"id":16771,"stock":14785.7,"modulus":90.0},{"yarnAlias":"B","yarnNo":"0999#本白","designFormId":873,"yarnName":"毛化纤","expectStock":4354.6,"standardNo":"12185020999P100","unitFormat":1,"yarnStandard":85.0,"yarnUsage":1.4,"composition":"[{\"type\":\"P\",\"content\":100,\"moistureRegain\":0.4}]","yarnId":8003,"yarnStrandNum":2,"id":16772,"stock":4354.0,"modulus":90.0}]);
}

//设计单纱线
export function loadYarnStandardBatch(data, callback) {
    return request({
        url: '/yarn_standard_batch/list',
        method: 'get',
        data,
        isYarn: true,
    }, callback);
    // return callback([{"yarnAlias":"A","yarnNo":"0999#本白","designFormId":873,"yarnName":"毛化纤","expectStock":200.6,"standardNo":"12148020999W80N20-y","unitFormat":1,"yarnStandard":48.0,"yarnUsage":24.1,"composition":"[{\"type\":\"W\",\"content\":80,\"moistureRegain\":16.0},{\"type\":\"N\",\"content\":20,\"moistureRegain\":4.5}]","yarnId":8487,"yarnStrandNum":2,"id":16769,"stock":200,"modulus":90.0},{"yarnAlias":"B","yarnNo":"0999#本白","designFormId":873,"yarnName":"毛化纤","expectStock":4354.6,"standardNo":"12185020999P100","unitFormat":1,"yarnStandard":85.0,"yarnUsage":1.4,"composition":"[{\"type\":\"P\",\"content\":100,\"moistureRegain\":0.4}]","yarnId":8003,"yarnStrandNum":2,"id":16770,"stock":4354.0,"modulus":90.0},{"yarnAlias":"A","yarnNo":"0999#本白","designFormId":873,"yarnName":"毛化纤","expectStock":-26144.6,"standardNo":"12148020999W80N20-y","unitFormat":1,"yarnStandard":48.0,"yarnUsage":22.2,"composition":"[{\"type\":\"W\",\"content\":80,\"moistureRegain\":16.0},{\"type\":\"N\",\"content\":20,\"moistureRegain\":4.5}]","yarnId":8487,"yarnStrandNum":2,"id":16771,"stock":14785.7,"modulus":90.0},{"yarnAlias":"B","yarnNo":"0999#本白","designFormId":873,"yarnName":"毛化纤","expectStock":4354.6,"standardNo":"12185020999P100","unitFormat":1,"yarnStandard":85.0,"yarnUsage":1.4,"composition":"[{\"type\":\"P\",\"content\":100,\"moistureRegain\":0.4}]","yarnId":8003,"yarnStrandNum":2,"id":16772,"stock":4354.0,"modulus":90.0}]);
}

//加载岗位列表
export function loadPost(data, callback) {
    return request({
        url: '/post/list_4_order',
        method: 'get',
        data,
        isUser: true,
    }, callback);
    // return callback([{"id":611,"name":"门市部","depId":610},{"id":541,"name":"业务部","depId":57},{"id":54,"name":"开发设计部","depId":10},{"id":566,"name":"原料仓库","depId":565},{"id":3456,"name":"纺纱车间","depId":606},{"id":261,"name":"纱线仓库","depId":61},{"id":55,"name":"织造车间","depId":45},{"id":631,"name":"坯布仓库","depId":630},{"id":806,"name":"染整车间","depId":487},{"id":3458,"name":"散染车间","depId":3457},{"id":1416,"name":"成品仓库","depId":1415}]);    //fixme
}

//指派任务
export function appointTask(data, callback) {
    return request({
        url: "/cloth_order/appoint_task",
        method: "post",
        type: "json",
        data,
        isYarn: true
    }, callback);
}

//接任务
export function acceptTask(data, callback) {
    return request({
        url: "/cloth_order/accept_task",
        method: "post",
        data,
        isFile: true,
        isYarn: true
    }, callback);
}

//驳回任务
export function rejectTask(data, callback) {
    return request({
        url: "/cloth_order/reject_task",
        method: "post",
        data,
        isFile: true,
        isYarn: true
    }, callback);
}

//完成任务
export function finishTask(data, callback) {
    return request({
        url: "/cloth_order/finish_task",
        method: "post",
        data,
        isFile: true,
        isYarn: true
    }, callback);
}

//撤销任务
export function cancelTask(data, callback) {
    return request({
        url: "/cloth_order/cancel_task",
        method: "post",
        data,
        isFile: true,
        isYarn: true
    }, callback);
}

//加载订单任务列表
export function loadOrderTaskBySubOrder(data, callback) {
    return request({
        url: '/cloth_order/list_task_by_sub_order',
        method: 'get',
        data,
        isYarn: true,
        isEmpty: true,      //回调不抛异常
    }, callback);

    // return callback([{"appointorName":"王进芸","executiveRemark":"","appointAt":"2022-08-08 21:18:14","executiveId":0,"executiveName":"","depPost":"3457_3458","appointRemark":"","appointorId":104,"id":1030,"status":1},{"appointorName":"王进芸","executiveRemark":"","appointAt":"2022-08-08 21:18:14","acceptAt":"2022-08-09 15:43:45","executiveId":101,"executiveName":"何定刚","depPost":"487_806","appointRemark":"","appointorId":104,"id":1029,"status":2},{"appointorName":"王进芸","executiveRemark":"","appointAt":"2022-08-08 21:18:14","executiveId":0,"executiveName":"","depPost":"630_631","appointRemark":"","appointorId":104,"id":1028,"status":1},{"appointorName":"王进芸","executiveRemark":"","appointAt":"2022-08-08 21:18:14","executiveId":0,"executiveName":"","depPost":"61_261","appointRemark":"","appointorId":104,"id":1027,"status":1},{"appointorName":"王进芸","executiveRemark":"","appointAt":"2022-08-08 21:18:14","executiveId":0,"executiveName":"","depPost":"45_55","appointRemark":"","appointorId":104,"id":1026,"status":1},{"appointorName":"王进芸","executiveRemark":"","appointAt":"2022-08-08 21:18:14","executiveId":0,"executiveName":"","depPost":"606_3456","appointRemark":"","appointorId":104,"id":1025,"status":1},{"appointorName":"王进芸","executiveRemark":"","appointAt":"2022-08-08 21:18:14","executiveId":0,"executiveName":"","depPost":"565_566","appointRemark":"","appointorId":104,"id":1024,"status":1},{"appointorName":"王进芸","executiveRemark":"","appointAt":"2022-08-08 21:18:14","executiveId":0,"executiveName":"","depPost":"10_54","appointRemark":"","appointorId":104,"id":1023,"status":1},{"appointorName":"三老板","executiveRemark":"已完成","appointAt":"2022-08-08 11:04:58","remarkAt":"2022-08-08 21:02:19","acceptAt":"2022-08-08 21:02:02","executiveId":104,"executiveName":"王进芸","depPost":"57_541","appointRemark":"测试","appointorId":118,"id":1008,"status":3}]);   //fixme
}

//取消订单订单
export function cancelOrder(data, callback) {
    return request({
        url: "/cloth_order/cancel_order",
        method: "post",
        data,
        isFile: true,
        isYarn: true
    }, callback);
}

//更改品号
export function changeSubOrderDesign(data, callback) {
    return request({
        url: "/cloth_order/change_sub_order_design",
        method: "post",
        type: "json",
        data,
        isYarn: true
    }, callback);
}

/* 加载订单部门配置 */
export function loadDepConfig(data, callback) {
    return request({
        url: "/cloth_order/list_dep_config",
        method: "get",
        data,
        isYarn: true,
    }, callback);
}

/* 处理环节 */
export function handleStep(data, callback) {
    return request({
        url: "/cloth_order/process_step",
        method: "post",
        data,
        isYarn: true,
        type: "json",
        isEmpty: true,
    }, callback);
}